Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LibOS] Fix bug of RLIMIT_STACK being overwritten in child #1976

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

dimakuv
Copy link
Contributor

@dimakuv dimakuv commented Aug 19, 2024

Description of the changes

Previously, the resource limit RLIMIT_STACK (maximum size of the process stack, in bytes) was overwritten in the child process, after fork. Thus, if the parent used setrlimit(RLIMIT_STACK), the effect of this was lost in the child. This PR fixes this bug, and adds a LibOS test to verify the correct behavior.

Fixes #1974

Noticed while reviewing #1973.

How to test this PR?

New LibOS test was added.


This change is Reviewable

Copy link
Contributor Author

@dimakuv dimakuv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 7 files reviewed, 2 unresolved discussions, not enough approvals from maintainers (2 more required), not enough approvals from different teams (1 more required, approved so far: Intel)

a discussion (no related file):
This PR is based on top of #1973, thus requires that one to be merged first.



libos/src/libos_init.c line 303 at r1 (raw file):

        return 0;

    stack_size = ALLOC_ALIGN_UP(stack_size);

Note that stack size doesn't need to be aligned when setting the resource limit RLIMIT_STACK. That's what Linux does -- it doesn't silently adjust the stack size, instead Linux just writes whatever stack size the user supplies to it.

Thus I moved this alignment of the stack further down in this function.

@mkow mkow force-pushed the dimakuv/add-rlimit-noproc-manifest branch from aeacda6 to ca534ce Compare August 26, 2024 12:20
Base automatically changed from dimakuv/add-rlimit-noproc-manifest to master August 27, 2024 10:50
Copy link
Contributor

@efu39 efu39 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and looks good to me.

Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel)

@dimakuv dimakuv added the P: 0 label Oct 29, 2024
@dimakuv dimakuv force-pushed the dimakuv/migrate-rlimit-stack-child branch from e4de968 to f9de8b1 Compare October 29, 2024 18:08
Copy link
Contributor Author

@dimakuv dimakuv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @efu39 !

Reviewable status: 2 of 7 files reviewed, 1 unresolved discussion, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel) (waiting on @efu39)

a discussion (no related file):

Previously, dimakuv (Dmitrii Kuvaiskii) wrote…

This PR is based on top of #1973, thus requires that one to be merged first.

Done, rebased


Copy link
Contributor

@kailun-qin kailun-qin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 7 files at r1, 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel) (waiting on @dimakuv)


libos/test/regression/rlimit_stack.c line 5 at r2 (raw file):

#include <errno.h>
#include <fcntl.h>

Do we need this?

Code quote:

#include <fcntl.h>

libos/test/regression/rlimit_stack.manifest.template line 16 at r2 (raw file):

sgx.debug = true
sgx.edmm_enable = {{ 'true' if env.get('EDMM', '0') == '1' else 'false' }}
sgx.use_exinfo = {{ 'true' if env.get('EDMM', '0') == '1' else 'false' }}

Do we need this?

Code quote:

sgx.use_exinfo = {{ 'true' if env.get('EDMM', '0') == '1' else 'false' }}

Copy link
Contributor Author

@dimakuv dimakuv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 7 files reviewed, 3 unresolved discussions, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel), "fixup! " found in commit messages' one-liners (waiting on @efu39 and @kailun-qin)


libos/test/regression/rlimit_stack.c line 5 at r2 (raw file):

Previously, kailun-qin (Kailun Qin) wrote…

Do we need this?

Done.


libos/test/regression/rlimit_stack.manifest.template line 16 at r2 (raw file):

Previously, kailun-qin (Kailun Qin) wrote…

Do we need this?

Done. You're right, not required.

kailun-qin
kailun-qin previously approved these changes Oct 30, 2024
Copy link
Contributor

@kailun-qin kailun-qin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion, not enough approvals from different teams (1 more required, approved so far: Intel), "fixup! " found in commit messages' one-liners

@dimakuv
Copy link
Contributor Author

dimakuv commented Oct 30, 2024

Jenkins, retest pkg-apk-alpine3.17 please

Copy link
Member

@mkow mkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions, not enough approvals from different teams (1 more required, approved so far: Intel), "fixup! " found in commit messages' one-liners (waiting on @dimakuv)


libos/test/regression/rlimit_stack.c line 18 at r3 (raw file):

    CHECK(getrlimit(RLIMIT_STACK, &rlim));
    printf("old RLIMIT_STACK soft limit: %lu\n", (uint64_t)rlim.rlim_cur);
    uint64_t old_lim = (uint64_t)rlim.rlim_cur;

Just delete this and use rlim.rlim_cur directly in the IF?


libos/test/regression/rlimit_stack.c line 21 at r3 (raw file):

    /* make sure we can increase the current soft limit */
    if (old_lim >= (uint64_t)rlim.rlim_max)

Why the cast here?

Code quote:

(uint64_t)

libos/test/regression/rlimit_stack.c line 39 at r3 (raw file):

        /* NOTE: we currently don't test that the stack limit is indeed enforced */
        exit(0);
    } else {

Why is some part of the code inside else block and some outside? Both always execute together.


libos/test/regression/test_libos.py line 1103 at r3 (raw file):

        self.assertIn("TEST OK", stdout)

    def test_165_rlimit_stack(self):

Or maybe I'm missing something?

Suggestion:

def test_162_rlimit_stack(self):

Copy link
Contributor Author

@dimakuv dimakuv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 7 files reviewed, 5 unresolved discussions, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel), "fixup! " found in commit messages' one-liners (waiting on @kailun-qin and @mkow)


libos/test/regression/rlimit_stack.c line 18 at r3 (raw file):

Previously, mkow (Michał Kowalczyk) wrote…

Just delete this and use rlim.rlim_cur directly in the IF?

Done.


libos/test/regression/rlimit_stack.c line 21 at r3 (raw file):

Previously, mkow (Michał Kowalczyk) wrote…

Why the cast here?

Done.


libos/test/regression/rlimit_stack.c line 39 at r3 (raw file):

Previously, mkow (Michał Kowalczyk) wrote…

Why is some part of the code inside else block and some outside? Both always execute together.

Done.


libos/test/regression/test_libos.py line 1103 at r3 (raw file):

Previously, mkow (Michał Kowalczyk) wrote…

Or maybe I'm missing something?

Done.

Copy link
Member

@mkow mkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion, "fixup! " found in commit messages' one-liners

@mkow mkow force-pushed the dimakuv/migrate-rlimit-stack-child branch from d575ad8 to 93be2c2 Compare October 31, 2024 17:52
Previously, the resource limit `RLIMIT_STACK` (maximum size of the
process stack, in bytes) was overwritten in the child process, after
fork. Thus, if the parent used `setrlimit(RLIMIT_STACK)`, the effect of
this was lost in the child. This commit fixes this bug, and adds a LibOS
test to verify the correct behavior.

Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
Copy link
Member

@mkow mkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion

Copy link
Contributor

@kailun-qin kailun-qin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion

Copy link
Member

@mkow mkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@mkow mkow merged commit 93be2c2 into master Oct 31, 2024
26 checks passed
@mkow mkow deleted the dimakuv/migrate-rlimit-stack-child branch October 31, 2024 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LibOS] RLIMIT_STACK is reset to default value in child process
4 participants